//
//  HBBViewController.swift
//  PassValueDemo
//
//  Created by MAC on 2020/8/20.
//  Copyright © 2020 MAC. All rights reserved.
//

import UIKit

class HBBViewController: UIViewController {
    //声明全局变量，并初始化
    var textLabel = UILabel()
    override func viewDidLoad() {
        super.viewDidLoad()
        //传值按钮
        let ymBtn_01 = UIButton()
        ymBtn_01.frame = CGRect(x: 50, y: 130, width: view.frame.size.width - 100, height: 50)
        ymBtn_01.setTitle("跳转下级页面", for: .normal)
        ymBtn_01.backgroundColor = .brown
        ymBtn_01.tag = 10001
        ymBtn_01.addTarget(self, action: #selector(tiaozhuanyemianclick(sender:)), for: .touchUpInside)
        view.addSubview(ymBtn_01)
        
        //接收传值的标签
        textLabel.font = .systemFont(ofSize: 20)
        textLabel.frame = CGRect(x: 50, y: ymBtn_01.frame.origin.y+150, width: view.frame.size.width - 100, height: 50)
        textLabel.text = "空值"
        textLabel.numberOfLines = 0
        textLabel.lineBreakMode = .byWordWrapping
        textLabel.backgroundColor = .darkGray
        textLabel.textColor = UIColor.init(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.6)
        view.addSubview(textLabel)
        
        //提示标签
        let textLabel_1 = UILabel()
        textLabel_1.font = .systemFont(ofSize: 20)
        textLabel_1.frame = CGRect(x: 50, y: (textLabel.frame.origin.y+textLabel.frame.size.height)+50, width: view.frame.size.width - 100, height: 50)
        textLabel_1.text = "请先到下级页面中填写要传回的值"
        textLabel_1.numberOfLines = 0
        textLabel_1.lineBreakMode = .byWordWrapping
        textLabel_1.backgroundColor = .darkGray
        textLabel_1.textColor = .yellow
        textLabel_1.font = .systemFont(ofSize: 15)
        textLabel_1.textAlignment = .center
        view.addSubview(textLabel_1)
        
    }
    //实现传值按钮的监听方法
    @objc func tiaozhuanyemianclick(sender:UIButton){
        let aBBVC = ABBViewController()
        aBBVC.view.backgroundColor = .white
        aBBVC.title = "传值界面"
        //调用闭包获取传值，并赋值给标签
        aBBVC.bbchange = {
            (title:String) in
            //赋值给标签
            self.textLabel.text = title
            print("接收传值：",title)
        }
        self.navigationController?.pushViewController(aBBVC, animated: true)
    }
    
}
